package com.tbit.uqbike.webmanager.controller;

import com.tbit.uqbike.object.value.LoginInfo;
import com.tbit.uqbike.object.view.JsonResult;
import com.tbit.uqbike.service.business.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.validation.constraints.NotNull;

/**
 * @author MyWin E-mail:335918956@qq.com
 * @version 1.0
 * @createTime 2019-12-09 14:06
 */
@Validated
@RestController
@RequestMapping(value = "/code", produces = BaseController.MEDIA_JSON_UTF8)
public class CodeController extends BaseController {
    @Autowired
    private AccountService accountService;

    // 发送验证码
//    @OperateLog(module = ModuleEnum.VER_CODE, methods = MethodEnum.SEND_CODE)
    @RequestMapping("/sendCode")
    public JsonResult sendCode(@NotNull(message = "ver.brandId.notNull") Integer brandId,
                               @NotNull(message = "ver.country.notBlank") String country,
                               @NotNull(message = "ver.phone.notBlank") String phone,
                               @NotNull(message = "ver.code.type.notBlank") String type, HttpServletRequest request) {
        // 获取用户信息
        LoginInfo loginInfo = getLogin(request);
        accountService.sendCode(brandId, country, phone, type, loginInfo);
        // 返回数据
        return JsonResult.ok();
    }
}
